package com.pingtai.manage.action;

import java.util.Date;

import com.pingtai.ajax.entity.Notice;
import com.pingtai.indent.service.WeiboIndentService;
import com.pingtai.manage.service.NoticeService;
import com.pingtai.user.service.UserManagerService;
import com.pingtai.util.PaginationSupport;
import com.pingtai.xinlang.login.entity.LoginUser;

public class CookieManageAction {

	private UserManagerService userManagerService;
	private WeiboIndentService weiboIndentService;
	private NoticeService noticeManageService;
	private Integer currentPage;
	private Integer pageNum;
	private PaginationSupport paginationSupport;
	private LoginUser loginUser;
	
	
	
	public LoginUser getLoginUser() {
		return loginUser;
	}
	public void setLoginUser(LoginUser loginUser) {
		this.loginUser = loginUser;
	}
	public Integer getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	public Integer getPageNum() {
		return pageNum;
	}
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}
	public PaginationSupport getPaginationSupport() {
		return paginationSupport;
	}
	public void setPaginationSupport(PaginationSupport paginationSupport) {
		this.paginationSupport = paginationSupport;
	}
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	public WeiboIndentService getWeiboIndentService() {
		return weiboIndentService;
	}
	public void setWeiboIndentService(WeiboIndentService weiboIndentService) {
		this.weiboIndentService = weiboIndentService;
	}
	public NoticeService getNoticeManageService() {
		return noticeManageService;
	}
	public void setNoticeManageService(NoticeService noticeManageService) {
		this.noticeManageService = noticeManageService;
	}
	
	public String cookieManageUI(){
		if(currentPage>0) {
			pageNum = currentPage;
			currentPage = PaginationSupport.PAGESIZE*(currentPage-1);
		}
		
	    paginationSupport = noticeManageService.getLoginUserForPage(currentPage);
		return "success";
	}
	
	
	public String toChangeCookie(){
		loginUser = noticeManageService.getCookieById(loginUser.getId());
		return "success";
	}
	
	public String changeCookie(){
		String cookie = loginUser.getCookies();
		loginUser = noticeManageService.getCookieById(loginUser.getId());
		loginUser.setCookies(cookie);
		loginUser.setLastLoginDate(new Date());
		noticeManageService.updateLoginUser(loginUser);
		return "success";
	}
}
